package com.premnirmal.Magnet.app;

import com.premnirmal.magnet.library.Magnet;
import com.premnirmal.magnet.library.RemoveView;

import cs.help.tool.Log;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.components.Image;
import ohos.app.Context;

import org.junit.Test;

/**
 *  单元测试
 */
public class ExampleOhosTest {
    /**
     * 测试直接创建悬浮窗管理对象
     */
    @Test
    public void testMagnetBuild() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        Log.i("单元测试  testMagnetBuild");
        Magnet magnet = new Magnet(context);
        Log.i("单元测试  testMagnetBuild   是否创建成功: " + (magnet == null ? "否" : "是"));
    }

    /**
     * 创建悬浮窗
     * @return 悬浮窗控制类的对象
     */
    public Magnet createMagnet() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        Image image = new Image(context);
        return new Magnet.Builder(context)
                .setIconView(image)
                .setHideFactor(0.2f)
                .setShouldShowRemoveView(true)
                .setShouldStickToWall(true)
                .setRemoveIconShouldBeResponsive(true)
                .setInitialPosition(200, 200)
                .build();
    }

    /**
     * 测试创建悬浮窗
     */
    @Test
    public void testBuilderBuild() {
        Log.i("单元测试  testBuilderBuild");
        Magnet magnet = createMagnet();
        Log.i("单元测试  testBuilderBuild   magnet是否创建成功: " + (magnet == null ? "否" : "是"));
    }

    /**
     * 测试悬浮窗的显示
     */
    @Test
    public void testMagnetShow() {
        Log.i("单元测试  testMagnetShow");
        createMagnet().show();
        Log.i("单元测试  testMagnetShow   完成");
    }

    /**
     * 测试删除栏的创建
     */
    @Test
    public void testRemoveViewCreate() {
        Log.i("单元测试  testRemoveViewCreate");
        RemoveView removeView = createMagnet().getRemoveView();
        Log.i("单元测试  testRemoveViewCreate   removeView是否创建成功:" + (removeView == null ? "否" : "是"));
    }

    /**
     * 测试展示删除栏
     */
    @Test
    public void testRemoveViewShow() {
        Log.i("单元测试  testRemoveViewShow");
        RemoveView removeView = createMagnet().getRemoveView();
        removeView.show();
        Log.i("单元测试  testRemoveViewShow   removeview是否展示:" + (removeView.isShowing() ? "是" : "否"));
    }

    /**
     * 测试隐藏删除栏
     */
    @Test
    public void testRemoveViewHide() {
        Log.i("单元测试  testRemoveViewHide");
        RemoveView removeView = createMagnet().getRemoveView();
        removeView.show();
        Log.i("单元测试  testRemoveViewHide   removeview是否展示:" + (removeView.isShowing() ? "是" : "否"));
        Log.i("单元测试  testRemoveViewHide   调用hide");
        removeView.hide();
        Log.i("单元测试  testRemoveViewHide   removeview是否展示:" + (removeView.isShowing() ? "是" : "否"));
    }
}